<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var generateParenthesis = function (n) {
      const m = [['']];
      for (let i = 1; i <= n; i++) {
        const v = [];
        for (let j = 0; j < i; j++) {
          for (const p of m[j]) {
            for (const q of m[i - 1 - j]) {
              v.push(`${p}(${q})`);
            }
          }
        }
        m.push(v);
      }
      return m.at(-1);
    };
    console.log(generateParenthesis(3));

  </script>
</body>

</html>